package com.example.demo.common;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LoginAspect {

    @Pointcut("execution(* com.example.demo.controller.TestController.*(..))")
    public void pointcut(){}

    // 前置通知
    @Before("pointcut()")
    public void doBefore(){
        System.out.println("执⾏ Before ⽅法");
    }
    // 后置通知
    @After("pointcut()")
    public void doAfter(){
        System.out.println("执⾏ After ⽅法");
    }
    // return 之前通知
    @AfterReturning("pointcut()")
    public void doAfterReturning(){
        System.out.println("执⾏ AfterReturning ⽅法");
    }
    // 抛出异常之前通知
    @AfterThrowing("pointcut()")
    public void doAfterThrowing(){
        System.out.println("执⾏ doAfterThrowing ⽅法");
    }

    @Around("pointcut()")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        Object object = null;
        System.out.println("Around方法开始执行");
        object = joinPoint.proceed();
        System.out.println("Around方法结束执行");
        return object;
    }


}
